﻿/**
 * \brief A class representing the title screen
 * This screen will transition to a mode select screen
 */

using UnityEngine;

namespace KaoticSSB.Menus
{
	public class TitleScreen : MonoBehaviour 
	{
		public Texture BackgroundTexture;
		public AudioClip BackgroundMusic;

		private float delay = 1.0f;

		void Start () 
		{
			SoundManager.GetInstance().PlayMusicOverTime(BackgroundMusic, 3.0f);
		}

		void Update () 
		{

			delay -= Time.deltaTime;
			if(delay <= 0.0f)
			{
				if(Input.GetButtonDown("Action_Button"))
				{
					Application.LoadLevel ("ServerListScreen");
					SoundManager.GetInstance().StopMusicOverTime(3.0f);
				}
			}
		}
		
		public void OnGUI()
		{
			if(BackgroundTexture != null)
			{
				GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), BackgroundTexture);
			}

			//draw hud elements on top
			GUILayout.BeginHorizontal();
			GUILayout.Space (Screen.width - 105);
			GUILayout.BeginVertical();
			GUILayout.Space (Screen.height - 105);
			GUILayoutOption[] options = { GUILayout.Width(100), GUILayout.Height (25) };
			if(GUILayout.Button ("Play offline", options))
			{
				//go to mode select screen
				Application.LoadLevel("OfflineModeSelect");
			}
			if(GUILayout.Button ("Play online", options))
			{
				//go to server list screen
				Application.LoadLevel ("ServerListScreen");
			}
			if(GUILayout.Button ("Quit", options) || Input.GetKeyDown(KeyCode.Escape))				
			{
				Application.Quit();
			}
			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
		}
	}
}
